<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page, index) of pages" :key="index">
        <div class="icon" v-for="item of page" :key="item.id">
          <div class="icon-img">
            <img class="img" :src="item.imgUrl" alt="">
          </div>
          <p class="icon-desc">{{ item.desc }}</p>
        </div>
      </swiper-slide>
      <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    iconlist: Array
  },
  data () {
    return {
      swiperOption: {
        autoplay: false,
        pagination: '.swiper-pagination'
      }
    }
  },
  computed: {
    pages () {
      const pages = []
      this.iconlist.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" type="text/stylus" scoped>
@import '~styles/varibiles.styl'
@import '~styles/mixins.styl'
.icons >>> .swiper-container
  padding-bottom .3rem
.icons >>> .swiper-wrapper
  flex-flow wrap
  display -webkit-box
.icons >>> .swiper-container-horizontal > .swiper-pagination-bullets
  bottom 0px
.icons >>> .swiper-pagination-bullet
  width 6px
  height 6px
.icons >>> .swiper-pagination-bullet-active
  background: rgba(0,175,190,.8);
.icons
  overflow hidden
  display flex
  justify-content space-between
  align-items center
  flex-flow wrap
  background-color #FFF
  padding-top 0.1rem
  .icon
    float left
    width 25%
    overflow hidden
    text-align center
    padding-top .2rem
    .icon-desc
      margin-top .1rem
      ellipse()
    .icon-img
      display flex
      justify-content center
      align-items center
      .img
        width:1.1rem
        height:1.1rem
</style>
